// pages/project/project.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeIndex: '0',
    Y: 0,
    pageNo: 1,
    pageSize: 10,
    projectList: [],
    // 加载时第一次
    isonLoad: true,
    isproess: true,
    // 接单遮罩层
    isfromMask: false,
    // 合同遮罩层
    iscontractMak: false,
    // 是否勾选
    ischecked: false,
    // 是否显示可选框
    isCheck: false,
    issuccessMask: false,
    // 搜索时的项目名
    projectName: '',
    // 代办列表
    waitList: [],
    // 是否显示一键派单遮罩层
    ispaidan: false,
    isAll: false,
    issuccessMaskpaidan: false,
    isanimation:true
  },
  bindSubmit() {

  },
  btsa() {
    if (wx.getStorageSync('up') == false) {
      wx.setStorageSync('up', true)
      this.up = setTimeout(() => {
        wx.setStorageSync('up', false)
      }, 1000);
      let newprojectList = this.data.newprojectList.filter(item => item.isproess == true)
      if (newprojectList.length == 0) {
        wx.showToast({
          title: '请选择再派单',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
        wx.setStorageSync('up', false)
        return
      }
      let newprojectListiD = newprojectList.map(item => {
        return {
          id: item.id,
          token: app.token()
        }
      })
      console.log(newprojectListiD)




      newprojectListiD.forEach((item, index) => {

        this.saveProjectOrder(item).then((res) => {
          if (index == newprojectListiD.length - 1 && res == 0) {
            wx.setStorageSync('up', true)
            this.setData({
              issuccessMaskpaidan: true
            })
          }
        })

      })
    } else {

    }


  },
  // 一键派单






  saveProjectOrder(obj) {

    return new Promise((resolve, reject) => {
      wx.showLoading({
        title: '加载中',
        mask: true //显示透明蒙层 防止触摸穿透
      })
      wx.request({
        url: app.globalData.Interfaceurl + 'saveProjectOrder',
        method: "post",
        header: {
          "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
        },
        data: {
          userId: app.globalData.userId,
          token: obj.token,
          orderId: obj.id,
          operateType: 2
        },
        success: res => {
          wx.hideLoading()
          if (res.data.result == 0) {
            resolve(res.data.result)

          } else {
            wx.showToast({
              title: res.data.message,
              duration: 2500, //持续的时间
              icon: 'none', //图标
            })
          }

        },
        fail: err => {
          wx.showToast({
            title: '请求失败',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
        }
      })
    })
  },


  HidesuccessMaskpadian() {
    this.setData({
      issuccessMaskpaidan: false,
      pageNo: 1,
      pageSize: 10
    })

    this.getShopownerOrderPage()
    this.nohidepaidan()
  },

  all() {
    let newprojectList = this.data.newprojectList
    newprojectList.map(item => item.isproess = !this.data.isAll)
    this.setData({
      isAll: !this.data.isAll,
      newprojectList: newprojectList,
      isxuannum:newprojectList.length
    })
  },
  // 隐藏遮罩层
  nohidepaidan() {
    this.setData({
      ispaidan: false,
      newprojectList: [],
      // 选择了多少项目
      isxuannum: 0,
      isAll: false
    })
  },
  // 一键派单
  btnspaidan() {
    let newprojectList = this.data.projectList.filter(item => item.adviserId != '')
    this.setData({
      ispaidan: true,
      newprojectList: newprojectList,
      // 选择了多少项目
      isxuannum: 0,
      isAll: false,
      token: app.token()
    })
  },
  //选择
  bindcheckout(e) {
    let newprojectList = this.data.newprojectList
    newprojectList[e.currentTarget.dataset.index].isproess = !newprojectList[e.currentTarget.dataset.index].isproess
    let isxuannum = (newprojectList.filter(item => item.isproess == true)).length
    if (isxuannum == newprojectList.length) {
      this.setData({
        isAll: true
      })
    } else {
      this.setData({
        isAll: false
      })
    }

    this.setData({
      newprojectList: newprojectList,
      isxuannum: isxuannum
    })
  },
  // 跳转驳回,重新编辑
  gorejected(e) {
    wx.navigateTo({
      url: '/shopowner/pages/previewOrder/previewOrder?todo=rejected&orderId=' + e.currentTarget.dataset.id,
    })
  },
  // 底部待办
  catchtouchstart(e) {
    console.log(e)
    this.setData({
      stateY: e.changedTouches[0].clientY,
      yidon:e.changedTouches[0].clientY,
      isanimation:false
    })
  },
  catchtouchmove(e){
    let touchendclientY = e.changedTouches[0].clientY
    let cha = touchendclientY - this.data.yidon
    let Y=this.data.Y+cha
    if(Y>0){
      this.setData({
        Y: 0,
        yidon:touchendclientY
      })
    }else if(Y<-668){
      this.setData({
        Y: -668,
        yidon:touchendclientY
      })
    }else{
      this.setData({
        Y: Y,
        yidon:touchendclientY
      })
    }
  },
  catchtouchend(e) {
    let touchendclientY = e.changedTouches[0].clientY
    let cha = touchendclientY - this.data.stateY
    if (cha < -20) {
      this.setData({
        Y: -668,
        isanimation:true
      })
    } else if (cha > 20) {
      this.setData({
        Y: 0,
        isanimation:true
      })
    }
  },

  hideisfromMask() {
    this.setData({
      isfromMask: false
    })
  },
  gowal(e) {
    wx.setStorageSync('istab', true)
    let orderId = e.currentTarget.dataset.id
    let waitStatus = e.currentTarget.dataset.status
    let waitItemRecordId = e.currentTarget.dataset.waitid
    if (waitStatus == 1) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=dispatch&&orderId=' + orderId,
        })
      }))

    } else if (waitStatus == 2) {
      if (app.globalData.identity == 5 || app.globalData.identity == 8) {
        this.readWaitItem(waitItemRecordId).then((res => {
          wx.navigateTo({
            url: '/pages/projectDetails/projectDetails?orderId=' + orderId,
          })
        }))


      } else if (app.globalData.identity == 4) {
        this.readWaitItem(waitItemRecordId).then((res => {
          wx.navigateTo({
            url: '/pages/projectDetails/projectDetails?orderId=' + orderId,
          })
        }))

        // wx.navigateTo({
        //   url: '/supervisor/pages/construction/construction?orderId=' + orderId,
        // })
      }
    } else if (waitStatus == 3) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=finished&&orderId=' + orderId,
        })
      }))

    } else if (waitStatus == 4) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=delivery' + '&&orderId=' + e.currentTarget.dataset.id,
        })
      }))

    } else if (waitStatus == 5) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=chenkacceptance' + '&&orderId=' + e.currentTarget.dataset.id,
        })
      }))
      // wx.navigateTo({
      //   url: '/shopowner/pages/Inneracceptance/Inneracceptance?todo=check' + '&&orderId=' + e.currentTarget.dataset.id,
      // })
    } else if (waitStatus == 6) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=finished' + '&&orderId=' + e.currentTarget.dataset.id,
        })
      }))
      // wx.navigateTo({
      //   url: '/shopowner/pages/Inneracceptance/Inneracceptance?todo=check' + '&&orderId=' + e.currentTarget.dataset.id,
      // })
    } else if (waitStatus == 7) {
      this.readWaitItem(waitItemRecordId).then((res => {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=maintain&&orderId=' + e.currentTarget.dataset.id,
        })
      }))

    } else if (waitStatus == 8) {
      this.readWaitItem(waitItemRecordId).then((res => {
       let todo = 'design'
        wx.navigateTo({
          url: '/shopowner/pages/previewOrder/previewOrder?todo=' + todo + '&&orderId=' +  e.currentTarget.dataset.id,
        })

      }))
      // wx.navigateTo({
      //   url: '/shopowner/pages/previewOrder/previewOrder?todo=design' + '&&orderId=' + e.currentTarget.dataset.id,
      // })
    } else if (waitStatus == 9) {
      wx.navigateTo({
        url: '/pages/projectDetails/projectDetails?todo=finished&&orderId=' + e.currentTarget.dataset.id,
      })
    } else if (waitStatus == 10) {
      wx.navigateTo({
        url: '/pages/projectDetails/projectDetails?todo=delivery&&orderId=' + e.currentTarget.dataset.id,
      })
    }
  },
  // 86.读取待办事项
  readWaitItem(waitItemRecordId) {
    let t = this
    return new Promise((resolve, reject) => {
      wx.request({
        url: app.globalData.Interfaceurl + 'readWaitItem',
        method: "post",
        header: {
          "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
        },
        data: {
          waitItemRecordId: waitItemRecordId,

        },
        success: res => {
          wx.hideLoading()
          resolve("ok")

        },
        fail: err => {
          wx.showToast({
            title: '请求失败',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
        }
      })
    })
  },

  gowaitAll() {
    wx.navigateTo({
      url: '/pages/waitAll/waitAll',
    })
  },
  // 显示接单遮罩层
  bindReceiving(e) {

    this.setData({
      isfromMask: true,
      orderId: e.currentTarget.dataset.id,
      workId: e.currentTarget.dataset.workid
    })
    this.getOrderDetails(e.currentTarget.dataset.id)
  },

  // 确认接单
  bindSubmit() {
    this.setData({
      isfromMask: false,
      iscontractMak: true,
      token: app.token()
    })
    clearTimeout(this.chechtimeout)
    this.chechtimeout = setTimeout(() => {
      this.setData({
        isCheck: true,


      })
    }, 3500)
  },
  // 显示进度
  showproess(e) {
    console.log(e)
    let projectList = this.data.projectList
    projectList.forEach((item, index) => {
      if (e.currentTarget.dataset.index == index) {
        item.isproess = !item.isproess
      } else {
        item.isproess = false
      }

    })
    console.log(projectList)
    this.setData({
      projectList: projectList
    })
  },

  // 确定要接单
  bindAgree() {
    if (!this.data.ischecked) {
      wx.showToast({
        title: '请勾选协议',
        duration: 2500, //持续的时间
        icon: 'none', //图标
      })
      return
    }
    this.saveReceiveOrder()
  },
  // 不接单
  bindRefused() {
    this.setData({
      iscontractMak: false,
      ischecked: false,
      isCheck: false
    })
  },
  // 勾选协议
  bindChecked() {
    let ischecked = this.data.ischecked
    this.setData({
      ischecked: !ischecked
    })
  },
  // 隐藏成功遮罩层
  HidesuccessMask() {
    this.setData({
      issuccessMask: false,
      isCheck: false,
    })
    this.getOrderBricklayPage()
  },

  // 店长的待派单
  goorderAttachment(e) {
    let rebutDate = e.currentTarget.dataset.rebutdate
    let adviserId=e.currentTarget.dataset.adviserid
    let bptDepositFlag=e.currentTarget.dataset.bptdepositflag
    console.log(e)
    if (rebutDate != '') {
      wx.navigateTo({
        url: '/shopowner/pages/previewOrder/previewOrder?todo=rejected&orderId=' + e.currentTarget.dataset.id,
      })
    }else if(adviserId!=''&&this.data.identity==5){
      wx.navigateTo({
        url: '/shopowner/pages/previewOrder/previewOrder?todo=jiaju&orderId=' + e.currentTarget.dataset.id,
      })
    } 
    else if(bptDepositFlag==1&&this.data.identity==10){
      wx.navigateTo({
        url: '/shopowner/pages/previewOrder/previewOrder?todo=jiaju&orderId=' + e.currentTarget.dataset.id,
      })
    } 
    else {
      wx.navigateTo({
        url: '/shopowner/pages/orderAttachment/orderAttachment?id=' + e.currentTarget.dataset.id,
      })
    }
  },





  // 店长-项目列表
  getShopownerOrderPage() {
    let t = this
    wx.showLoading({
      title: '加载中',
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getShopownerOrderPage',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        projectStatus: t.data.typeIndex,
        pageNo: t.data.pageNo,
        pageSize: t.data.pageSize,
        keyword: t.data.projectName
      },
      success: res => {
        wx.hideLoading()
        let projectList = t.data.projectList
        res.data.page.list.forEach(item => {
          item.isproess = false
        })
        if (t.data.pageNo == 1) {
          projectList = res.data.page.list
        } else {
          projectList.push(...res.data.page.list)
        }
        t.setData({
          projectList: projectList,
          projectlast: res.data.page.last
        })
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
            icon: 'none', //图标
        })
      }
    })
  },
  // 岩板砖家项目列表
  getSuperviseOrderPage() {
    let t = this
    wx.showLoading({
      title: '加载中',
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getSuperviseOrderPage',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        projectStatus: t.data.typeIndex,
        pageNo: t.data.pageNo,
        pageSize: t.data.pageSize,
        keyword: t.data.projectName
      },
      success: res => {
        wx.hideLoading()
        let projectList = t.data.projectList
        res.data.page.list.forEach(item => {
          item.isproess = false
        })
        if (t.data.pageNo == 1) {
          projectList = res.data.page.list
        } else {
          projectList.push(...res.data.page.list)
        }
        t.setData({
          projectList: projectList,
          projectlast: res.data.page.last
        })
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
            icon: 'none', //图标
        })
      }
    })
  },


  // 瓦工项目列表
  getOrderBricklayPage() {
    let t = this
    wx.showLoading({
      title: '加载中',
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getOrderBricklayPage',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        projectStatus: t.data.typeIndex,
        pageNo: t.data.pageNo,
        pageSize: t.data.pageSize,
        keyword: t.data.projectName
      },
      success: res => {
        wx.hideLoading()
        let projectList = t.data.projectList
        res.data.page.list.forEach(item => {
          item.isproess = false
        })
        if (t.data.pageNo == 1) {
          projectList = res.data.page.list
        } else {
          projectList.push(...res.data.page.list)
        }
        t.setData({
          projectList: projectList,
          projectlast: res.data.page.last
        })
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },
  // 设计师项目列表
  getOrderDesignerPage() {
    let t = this
    wx.showLoading({
      title: '加载中',
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getOrderDesignerPage',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        projectStatus: t.data.typeIndex,
        pageNo: t.data.pageNo,
        pageSize: t.data.pageSize,
        keyword: t.data.projectName
      },
      success: res => {
        console.log(res)
        wx.hideLoading()
        let projectList = t.data.projectList
        res.data.page.list.forEach(item => {
          item.isproess = false
        })
        if (t.data.pageNo == 1) {
          projectList = res.data.page.list
        } else {
          projectList.push(...res.data.page.list)
        }
        t.setData({
          projectList: projectList,
          projectlast: res.data.page.last
        })
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },
  // 代办事项
  getWaitItem() {
    let t = this
    wx.showLoading({
      title: '加载中',
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getWaitItem',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
      },
      success: res => {
        console.log(res)
        wx.hideLoading()
        t.setData({
          waitList: res.data.waitItem
        })
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },


  // 18.项目详情
  getOrderDetails(orderId) {
    let t = this
    wx.showLoading({
      title: '加载中...', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getOrderDetails',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        orderId: orderId
      },
      success: res => {
        wx.hideLoading();
        t.setData({
          projectOrder: res.data.projectOrder,
          designList: res.data.designList,
          deliverList: res.data.deliverList,
          buildList: res.data.buildList,
          shopowner: res.data.shopowner,
          supervise: res.data.supervise,
          bricklay: res.data.bricklay,
          designer: res.data.designer,
          Imageurl: app.globalData.Imageurl,

        })
        if(t.data.yeahcProjectOrder&&t.data.yeahcProjectOrder.workId){
          let workObj=res.data.workList.filter(item=>item.id==t.data.yeahcProjectOrder.workId)
          t.setData({
            workObj:workObj[0]
          })
        }
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },


  // 32.瓦工接单
  saveReceiveOrder() {
    let t = this
    wx.showLoading({
      title: '加载中...', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'saveReceiveOrder',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        token: t.data.token,
        workId: t.data.workId
      },
      success: res => {
        wx.hideLoading();
        if (res.data.result == 0) {
          t.setData({
            iscontractMak: false,
            issuccessMask: true
          })
        } else {
          wx.showToast({
            title: res.data.message,
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          t.setData({
            token: app.token()
          })
        }

      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
            icon: 'none', //图标
        })
      }
    })
  },




  // 触底刷新
  bindscrolltolower() {
    console.log(11)
    if (this.data.pageNo >= this.data.projectlast) {
      return
    }
    this.setData({
      pageNo: this.data.pageNo + 1
    })
    if (app.globalData.identity == 5) {
      console.log('店长的项目列表')
      this.getShopownerOrderPage()
    } else if (app.globalData.identity == 4) {
      console.log('岩板砖家的项目列表')
      this.getSuperviseOrderPage()
    } else if (app.globalData.identity == 8) {
      console.log('设计师的项目列表')

    }
  },


  // 上传照片
  gounplone(e) {

   if(e.currentTarget.dataset.projectdestil.checkDeliverDate==''){
    wx.navigateTo({
      url: '/pages/projectDetails/projectDetails?orderId='+e.currentTarget.dataset.id
    })
   }else{
 if(e.currentTarget.dataset.projectdestil.buildProofFlag==1){
  wx.navigateTo({
    url: '/pages/projectDetails/projectDetails?orderId='+e.currentTarget.dataset.id+'&&todo=wagonlook&&projectdestil='+JSON.stringify(e.currentTarget.dataset.projectdestil),
  })
 }else{
  wx.navigateTo({
    url: '/bricklayer/pages/unplonePrice/unplonePrice?projectdestil=' + JSON.stringify(e.currentTarget.dataset.projectdestil),
  })
 }
   }
  },



  // 岩板砖家设计
  // bindDesign(e) {
  //   if (e.currentTarget.dataset.designdate == '') {
  //     wx.showToast({
  //       title: '该项目还没有设计',
  //       icon: "none"
  //     })
  //     return
  //   }
  //   wx.navigateTo({
  //     url: '/supervisor/pages/design/design?id=' + e.currentTarget.dataset.id,
  //   })
  // },
  // 跳转施工
  construction(e) {
    if (app.globalData.identity == 5 || app.globalData.identity == 8) {
      wx.navigateTo({
        url: '/shopowner/pages/construction/construction?orderId=' + e.currentTarget.dataset.id,
      })
    } else if (app.globalData.identity == 4) {
      wx.navigateTo({
        url: '/supervisor/pages/construction/construction?orderId=' + e.currentTarget.dataset.id,
      })
    }

  },

  //   选择项目状态
  bindType(e) {
    this.setData({
      typeIndex: e.currentTarget.dataset.index,
      pageNo: 1,
      pageSize: 10,
      projectList: [],
    })
    if (this.data.identity == 5 || this.data.identity == 10) {
      this.getShopownerOrderPage()
    } else if (this.data.identity == 4) {
      this.getSuperviseOrderPage()
    } else if (this.data.identity == 6) {
      this.getOrderBricklayPage()
    } else if (this.data.identity == 8) {
      this.getOrderDesignerPage()
    }
  },




  // 内验收
  bindacceptance(e) {
    let todo = e.currentTarget.dataset.todo
    let item = e.currentTarget.dataset.item
    // if (item.deliverDate == '' || item.designDate == '') {
    //   return
    // }


    if (todo == 'acceptance') {
      // wx.navigateTo({
      //   url: '/pages/projectDetails/projectDetails?todo=' + todo + '&&orderId=' + e.currentTarget.dataset.id,
      // })
    } else {
      //  
      wx.navigateTo({
        url: '/supervisor/pages/Inneracceptance/Inneracceptance?todo=' + todo + '&&orderId=' + e.currentTarget.dataset.id,
      })
    }
  },
  // 店长验收
  bindcheck(e) {

  },
  // 店长设计
  // binddesign(e) {
  //   let todo = e.currentTarget.dataset.todo
  //   if (todo == 'design') {
  //     wx.navigateTo({
  //       url: '/shopowner/pages/previewOrder/previewOrder?todo=' + todo + '&&orderId=' + e.currentTarget.dataset.id,
  //     })
  //   } else {
  //     wx.navigateTo({
  //       url: '/shopowner/pages/ProductDrawing/ProductDrawing?todo=' + todo + '&&orderId=' + e.currentTarget.dataset.id,
  //     })
  //   }
  // },

  // 岩板砖家配送
  goDelivery(e) {
    // if (e.currentTarget.dataset.deliverdate == '') {
    //   wx.showToast({
    //     title: '该项目店长还没有配送',
    //     icon: "none"
    //   })
    //   return
    // }

  },
  // 店长配送
  // bindshopDelivery(e) {
  //   let todo = e.currentTarget.dataset.todo
  //   if (todo == 'priviewdelivery') {
  //     wx.navigateTo({
  //       url: '/shopowner/pages/previewOrder/previewOrder?todo=previewDeparture' + '&&orderId=' + e.currentTarget.dataset.id,
  //     })
  //   } else {
  //     wx.navigateTo({
  //       url: '/pages/projectDetails/projectDetails?todo=' + todo + '&&orderId=' + e.currentTarget.dataset.id,
  //     })
  //   }
  // },

  // 岩板砖家派单
  bindsupdispatch(e) {

    wx.navigateTo({
      url: '/pages/projectDetails/projectDetails?todo=dispatch&&orderId=' + e.currentTarget.dataset.id,
    })

  },
  // 店长完工
  goshopfinished(e) {
    wx.navigateTo({
      url: '/pages/projectDetails/projectDetails?todo=finished&&orderId=' + e.currentTarget.dataset.id,
    })
  },
  // 岩板砖家完工
  gosubfinished(e) {
    wx.navigateTo({
      url: '/pages/projectDetails/projectDetails?todo=finished&&orderId=' + e.currentTarget.dataset.id,
    })
  },

  // 跳转到项目详情
  goProjectDetails(e) {
    let item = e.currentTarget.dataset.item
    let id = item.id
    let todo = ''


    if (this.data.identity == 5 || this.data.identity == 10) {

      if (item.designDate == '') {
        todo = 'design'
        wx.navigateTo({
          url: '/shopowner/pages/previewOrder/previewOrder?todo=' + todo + '&&orderId=' + id,
        })
      } else if (item.deliverDate == ''&&item.receiveFlag==1) {
        todo = 'delivery'
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=' + todo + '&&orderId=' + id,
        })
      } else if (item.checkFlag == 1) {
        let todo = 'chenkacceptance'
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=' + todo + '&&orderId=' + id,
        })



      } else {


        //  return
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?orderId=' + id+'&&todo="" '
        })
      }




    } else if (this.data.identity == 4) {
      if (item.deliverDate != '' && item.checkDeliverDate == '') {

        todo = 'delivery'

        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=' + todo + '&&orderId=' + id,
        })


      } else if (item.deliverDate != '' && item.checkDeliverDate != '' && item.checkDate == '') {
        todo = 'acceptance'
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?todo=' + todo + '&&orderId=' + id,
        })
      } else {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?orderId=' + id
        })
      }


    } else if (this.data.identity == 8) {
      if (item.designDate == '') {
        todo = 'design'
        wx.navigateTo({
          url: '/shopowner/pages/previewOrder/previewOrder?todo=' + todo + '&&orderId=' + id,
        })
      } else {
        wx.navigateTo({
          url: '/pages/projectDetails/projectDetails?orderId=' + id
        })
      }
    } else {
      wx.navigateTo({
        url: '/pages/projectDetails/projectDetails?orderId=' + id
      })
    }








  },
  goprojectusr(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/projectDetails/projectDetails?orderId=' + id
    })
  },
  // 搜索项目
  bindconfirm() {
    this.setData({
      pageNo: 1,
      pageSize: 10,
      typeIndex: "",

    })
    if (app.globalData.identity == 5) {
      this.getShopownerOrderPage()
    } else if (app.globalData.identity == 4) {

      this.getSuperviseOrderPage()
    } else if (app.globalData.identity == 6) {
      this.getOrderBricklayPage()
    } else if (app.globalData.identity == 8) {
      console.log('设计师的项目列表')
      this.getOrderDesignerPage()
    }
  },
  // 店长保养
  gomaintain(e) {
    let gomaintain = e.currentTarget.dataset.guaranteenum

    if (gomaintain == '') {
      wx.navigateTo({
        url: '/pages/projectDetails/projectDetails?todo=maintain&&orderId=' + e.currentTarget.dataset.id,
      })
    } else {
      wx.navigateTo({
        url: '/shopowner/pages/guaranteedetail/guaranteedetail?orderId=' + e.currentTarget.dataset.id,
      })
    }

  },
  cir() {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let myTab = this.selectComponent('#myTab'); // 页面获取自定义组件实例
    myTab.gettabList(); // 通过实例调用组件事件
    if(wx.getStorageSync('wagon')==2){
      this.setData({
        typeIndex:2
      })
      wx.removeStorageSync('wagon')
    }
    if (app.globalData.identity == 5 || app.globalData.identity == 10) {
      this.getShopownerOrderPage()
      this.getWaitItem()
    } else if (app.globalData.identity == 4) {
      console.log('岩板砖家的项目列表')
      this.getSuperviseOrderPage()
      this.getWaitItem()
    } else if (app.globalData.identity == 6) {
      console.log('瓦工的项目列表')

      this.getOrderBricklayPage()

    } else if (app.globalData.identity == 8) {
      console.log('设计师的项目列表')
      this.setData({
        typeIndex: 1
      })
      this.getOrderDesignerPage()
      this.getWaitItem()
    }





    this.setData({
      identity: app.globalData.identity,
      Imageurl: app.globalData.Imageurl,

    })

  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      identity:app.globalData.identity
    })
    let myTab = this.selectComponent('#myTab'); // 页面获取自定义组件实例
    myTab.gettabList(); // 通过实例调用组件事件
    wx.setStorageSync('up', false)
    if(wx.getStorageSync('wagon')==2){
      this.setData({
        typeIndex:2
      })
      wx.removeStorageSync('wagon')
    }
    if (wx.getStorageSync('istab') == true) {
     
      if (this.data.isonLoad == false) {
        this.setData({
          pageNo: 1,
          pageSize: 10
        })
        if (app.globalData.identity == 5 || app.globalData.identity == 10) {
          console.log('店长的项目列表')
          this.getShopownerOrderPage()
          this.getWaitItem()
        } else if (app.globalData.identity == 4) {
          console.log('岩板砖家的项目列表')
          this.getSuperviseOrderPage()
          this.getWaitItem()
        } else if (app.globalData.identity == 6) {
          this.getOrderBricklayPage()

        } else if (app.globalData.identity == 8) {
          console.log('设计师的项目列表')
          this.getOrderDesignerPage()
          this.getWaitItem()
        }
      } else {
        this.setData({
          isonLoad: false
        })
      }
      this.setData({
        identity: app.globalData.identity,
        Imageurl: app.globalData.Imageurl,
  
      })
      wx.setStorageSync('istab', false)

    }

  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    // 瓦工触底刷新
    if (app.globalData.identity == 6) {
      if (this.data.pageNo >= this.data.projectlast) {
        return
      }
      this.setData({
        pageNo: this.data.pageNo + 1
      })
      this.getOrderBricklayPage()
    } else if (app.globalData.identity == 8) {
      if (this.data.pageNo >= this.data.projectlast) {
        return
      }
      this.setData({
        pageNo: this.data.pageNo + 1
      })
      this.getOrderDesignerPage()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    wx.removeStorageSync("up")
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    wx.removeStorageSync("up")
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },



  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})